<!DOCTYPE html>
<html lang="zh-cn">
<head>
	{include file="common/header" /}
	{include file="common/css" /}
	{include file="common/js" /}
</head>

<body>
    <div id="wrapper">
		{include file="common/dialog" /}
		{include file="common/navbar" /}
        <div id="page-wrapper">			
			<div class="row" id="first_row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
							其他相关 - <span class="table_title">留言列表</span>                            
                        </div>
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-hover" id="datalist">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>内容</th>
                                            <th>时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>                            
							<div id="page_nav">
								<span id="page_index">页次 <span id="page">1</span> / <span id="page_count">10</span></span>
								<button class="btn btn-outline btn-link" type="button" id="page_first">首页</button>
								<button class="btn btn-outline btn-link" type="button" id="page_prev">上一页</button>
								<button class="btn btn-outline btn-link" type="button" id="page_next">下一页</button>
								<button class="btn btn-outline btn-link" type="button" id="page_last">末页</button>
							</div>
                        </div>
                    </div>
                </div>
            </div>
            <script src="{$Think.config.web_res_root}mgr/js/feedback/show.js"></script>	
<script>
var curr_page = 1;
var page_count = 1;

function show_data(page) {
	
	var data = {
		get_data: 1,
		page: page
	};	
	$.ajax({
		url: cfg.web_root + "mgr/feedback/show",
		type: "get",
		dataType: "json",
		data: data,
		beforeSend: function() {
			
		},
		success: function(res, status) {
			if(res.code == 0) {
				
				$("#datalist > tbody").empty();
				if(res.data.list) {
					for(var i = 0; i < res.data.list.length; i++) {				
						var row = "<tr>";
						row += "<td>" + res.data.list[i].id + "</td>"
						row += "<td>" + res.data.list[i].content + "</td>";
						row += "<td>" + res.data.list[i].add_time + "</td>";
						row += "<td><button class=\"btn btn-outline btn-link btn-xs\" type=\"button\" id=\"id_" + res.data.list[i].id + "\" data-id=\"" + res.data.list[i].id + "\">删除</button></td>";
						row += "</tr>";
						
						$("#datalist > tbody").append(row);
					}
				}
								
				page = res.data.page;
				page_count = res.data.page_count;				
				$("#page").html(page);
				$("#page_count").html(page_count);
				
				//点击删除
				$("button[id ^= 'id_']").click(function() {					
					var curr_obj = $(this);			
					var data = {
						id: curr_obj.attr("data-id")
					};
					$("#dialog_confirm").find(".modal-body").html("确定删除吗？");
					$("#dialog_confirm").modal('show');
					$("#dialog_confirm_btn").unbind().click(function() {
						
						$.ajax({
							url: cfg.web_root + "mgr/feedback/del",
							type: "get",
							dataType: "json",
							data: data,
							beforeSend: function() {
								curr_obj.attr("disabled", true);
							},
							success: function(res, status) {
								$("#dialog_confirm").modal("hide");						
								if(res.code == 0) {
									
									show_data(curr_page);
								}
								else {
									$("#dialog_alert").find(".modal-body").html(res.msg);
									$("#dialog_alert").modal("show");		
								}
							},
							complete: function() {
								curr_obj.attr("disabled", false);
							}
						});
						
					});
					
				});
			}
		},
		complete: function() {
			
		}
	});
	
}

$(function() {
	
	show_data(curr_page);		
	$("#page_first").click(function() {
		curr_page = 1;		
		show_data(curr_page);	
	});
	$("#page_prev").click(function() {
		curr_page--;
		if(curr_page < 1)
			curr_page = 1;
		show_data(curr_page);	
	});
	$("#page_next").click(function() {
		curr_page++;
		if(curr_page > page_count)
			curr_page = page_count;
		show_data(curr_page);
	});
	$("#page_last").click(function() {
		curr_page = page_count;		
		show_data(page_count);	
	});
		
});
</script>		
        </div>
    </div>

</body>
</html>
